/**
* A wrapper of the DOMElement object
* @class minjs.Element
*/
/**
* Creates the minjs.Element object
* @constructor minjs.Element
* @param {DOMElement} el - 
*/
minjs.Element = function(el) {
	if(el){
		this.getDOMElement = function(){return el;}
	}
}

minjs.Element.get = function(id){
	var el = document.getElementById(id);
	return el ? new minjs.Element(el) : null;
}

minjs.Element.create = function(tagname){
	var el = document.createElement(tagname);
	return el ? new minjs.Element(el) : null;
}

minjs.Element.prototype.getClassName = function(){
	return this.getDOMElement().className;
}

minjs.Element.prototype.setClassName = function(cn){
	this.getDOMElement().className = cn;
}

minjs.Element.prototype.addClassName = function(cn){
	if(this.getDOMElement().className.indexOf(cn) == -1)
		this.getDOMElement().className += " " + cn;
}

minjs.Element.prototype.removeClassName = function(cn){
	var str = " " + cn;
	var CN = this.getDOMElement().className;
	var idx = CN.indexOf(str); 
	if(idx > -1) 
		this.getDOMElement().className = CN.slice(0, idx) + CN.slice(idx + str.length);
}

minjs.Element.prototype.setTitle = function(text){
	this.getDOMElement().setAttribute("title", text);
}

minjs.Element.prototype.getTitle = function(){
	return this.getDOMElement().getAttribute("title");
}

minjs.Element.prototype.addEventListener = function(event, handler){
	if(window.addEventListener)
		//this.getDOMElement().addEventListener(event, handler, false);
		this.getDOMElement().addEventListener(event, function(e){handler(new minjs.Event(e));}, false);
	else if(window.attachEvent)
		//this.getDOMElement().attachEvent("on" + event, function(){handler(window.event);});
		this.getDOMElement().attachEvent("on" + event, function(){handler(new minjs.Event(window.event));});
}

minjs.Element.prototype.getInnerHTML = function(){
	return this.getDOMElement().innerHTML;
}

minjs.Element.prototype.setInnerHTML = function(html){
	return this.getDOMElement().innerHTML = html;
}

minjs.Element.prototype.add = function(child){
	this.getDOMElement().appendChild(child.getDOMElement());
}

minjs.Element.prototype.remove = function(child){
	this.getDOMElement().removeChild(child.getDOMElement());	// TODO: add child-parent relationship confirmation ???
}

minjs.Element.prototype.setStyle = function(style){
	this.getDOMElement().setAttribute("style", style);
}

minjs.Element.prototype.addStyle = function(style){
	var oldStyle = this.getDOMElement().getAttribute("style");
	this.getDOMElement().setAttribute("style", (oldStyle ? oldStyle : "") + style);
}

minjs.Element.prototype.setAttribute = function(name, value){
	this.getDOMElement().setAttribute(name, value);
}

minjs.Element.prototype.getAttribute = function(name){
	return this.getDOMElement().getAttribute(name);
}

minjs.Element.prototype.setValue = function(value){
	this.getDOMElement().value = value;
}

minjs.Element.prototype.getValue = function(){
	return this.getDOMElement().value;
}



